#!/usr/bin/python2.6
# intelligenre.py
# feed it a folder and it will write you some spiffy
# genre tags courtesy of last.fm. no account necessary!

import logging
import logging.config
import string
from mutagen_interface import MutagenInterface
from getopt import getopt
from grabtags import GrabTags, Tag

LOG_FILE="intelligenre.log"
LOG_CONF="log.conf"
logging.config.fileConfig(LOG_CONF)
LOGGER = logging.getLogger("logger")

def usage():
    pass

# For console use
def select_tags(tags):
    selected_tags = []
    prompt_str = """
### Tag Selection ###
Below are the tags I was able to fetch from Last.FM.
Please enter the ID numbers of tags you would like to
use, separated by commas. ie: 1, 3, 2, 10 You may also
enter a single 0 to cancel or enter nothing to auto-accept
the top 10 tags.\n
 #\tCount\tTag
--\t-----\t-----------------------------"""
    for key, tag in tags.items():
        prompt_str = "%s\n#%s\t%s\t%s" % (prompt_str, tag['number'], tag['count'], string.capwords(tag['name']))

    prompt_str = "%s\nSelection: " % prompt_str
    selections = input(prompt_str)
    selections = selections.split(",")

    for selection in selections:
        if selection == "":
            LOGGER.info("Default tags selected.")
            for tag in tags: selected_tags.append(tag)
            break

        #LOGGER.debug("Tag keys: %s" % tags.keys()) # superfluous
        if int(selection) in tags.keys():
            selected_tags.append(tags[int(selection)])
        else: LOGGER.warning("Tag number %s doesn't exist. Try it again but pay attention this time." % selection)

    LOGGER.debug("Selected Tags: %s" % selected_tags)
    return selected_tags

def main():
    LOGGER.info("intelligenre started")

    mt = MutagenInterface()
    mt.get_artist("Deadmau5_03_Careless.mp3")

    #grabtags = GrabTags(LOGGER,"queen")
    #for key, tag in grabtags.tags.items():
      #print("%s - %s" % (tag.get_name(), tag.get_count()))


if __name__=="__main__":
    main()
